#!/bin/bash
set -e

echo "Running cxxbridge..."
mkdir -p gen

# 先确保项目编译通过
echo "Building with cxxbridge feature enabled..."
cargo build --features cxxbridge

# 使用 RUSTFLAGS 确保 feature 被启用
echo "Generating C++ bindings..."

# 设置 RUSTFLAGS 来启用 feature
export RUSTFLAGS="--cfg=feature=\"cxxbridge\""

# 生成 C++ 头文件
cxxbridge src/entry/user_auth_ffi.rs --header > gen/cxx_bridge_user_auth_ffi.h

# 生成 C++ 源文件  
cxxbridge src/entry/user_auth_ffi.rs > gen/cxx_bridge_user_auth_ffi.cpp

echo "cxxbridge generation completed successfully!"
echo "Generated files:"
echo "  - gen/cxx_bridge_user_auth_ffi.h (C++ header)"
echo "  - gen/cxx_bridge_user_auth_ffi.cpp (C++ source)"